#include <stdio.h>
#include <stdlib.h>
#include <stddef.h>
#include <string.h>

#define BUFFER_SIZE 1024

int main(int argc, char **argv) {
        char ch                         = 0;
        char *buffer                    = NULL;
        FILE *fd                        = NULL;
        unsigned long count             = 0;
        unsigned long line_number       = 0;

        if (argc != 3) {
            fprintf(stderr, "USAGE: startat <file> <line number>\n");
            exit(1);
        }

        if ((fd = fopen(argv[1], "r")) == NULL) {
            perror("Could not open file\n");
            exit(1);
        }
        
        line_number = atoi(argv[2]);
        if (line_number <= 0) {
            line_number = 1;
        }
        buffer = (char*)malloc(BUFFER_SIZE);

        for (count = 0; (count < line_number-1); count++) {
            while ((ch = getc(fd)) != '\n');
        }

        while (fgets(buffer, BUFFER_SIZE, fd) != NULL)
            printf("%s", buffer);

        free(buffer);
        fclose(fd);
        return 0;
}

